<template>
    <div class="article-list">
        <ul v-show="props.list.length">
            <li
                v-for="(item, index) in props.list"
                :key="index"
                class="article-item"
            >
                <NuxtLink :to="{path:`/article/detail/${item.id}`}" class="w-full">
                    <div class="item-content">
                        <div class="cont" :style="{width: item.image?'calc(100% - 160px)':'100%'}">
                            <div class="title truncate">
                                {{ item.title }}
                            </div>
                            <div class="desc line-clamp-4">
                                {{ item.desc }}
                            </div>
                        </div>
                        <div class="image" v-if="item.image">
                            <img :src="item.image" alt="图片" />
                        </div>
                    </div>
                    <div class="item-bottom">
                        <span class="cate-name" v-show="item.cate_name">
                            分类：{{ item.cate_name || "" }}
                        </span>
                        <span class="views">
                            阅读：{{ item.actual_hits + item.init_hits }}
                        </span>
                        <span class="create-time">
                            发布时间：{{ item.create_time }}
                        </span>
                    </div>
                </NuxtLink>
            </li>
        </ul>
        <div v-show="!props.list.length" class="flex justify-center items-center">
            <div class="p-[20px] text-center">
                <img src="/assets/images/no_data.png" width="120px" alt="图片" />
                <p class="text-lg mt-2">暂无数据</p>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
const props = defineProps({
    list: { type: Array as any, default: [] },
});
</script>
<style lang="scss" scoped>
.article-list {
    .no-data {
        text-align: center;
    }

    .article-item {
        display: flex;
        align-items: center;
        padding: 10px 20px;

        .item-content {
            display: flex;
            justify-content: space-between;
            width: 100%;

            .cont {

                .title {
                    padding: 5px 0 15px 0;
                    color: #424242;
                    font-size: 24px;
                    line-height: 30px;
                    text-overflow: ellipsis;
                }

                .title a:hover {
                    color: #06c;
                }

                .desc {
                    line-height: 20px;
                    font-size: 15px;
                }
            }

            .image {
                padding-left: 20px;
                img {
                    width: 120px;
                    object-fit: contain;
                }
            }
        }

        .item-bottom {
            padding: 5px 0;
            font-size: 12px;
            opacity: 0.65;
            border-bottom: 1px solid #ddd;

            span {
                margin-right: 15px;
            }

            .cate-name {
                font-weight: 400;
                line-height: 18px;
            }
        }
    }
}
</style>
